from configparser import ConfigParser
import json

cfg=ConfigParser()
cfg.read('test.ini')
#将文件内容转换为字典
d={section:{m:n for m,n in cfg.items(section)} for section,v in cfg.items()}

with open('test.json','w+',encoding='utf-8') as f:
    json.dump(d,f)
    #验证
    print('验证：')
    f.seek(0,0)
    print(f.read())
